package com.mercury.tests;
import org.hibernate.*;
import com.mercury.beans.*;
public class Test2a {
	public static void main(String[] args){
		Session session =  HibernateUtil.currentSession();
		
		//Update a record(1)
		String hql="update User set age=20 where name=:name";
		Transaction tx = session.beginTransaction();
		Query query = session.createQuery(hql);
		query.setString("name", "peter");
		query.executeUpdate();
		tx.commit();
		
		//update a record(2)
		tx = session.beginTransaction();
		User user = (User)session.load(User.class, "Carson"); //user class    primary key
		user.setAge(18);
		tx.commit();
		
		user =(User)session.get(User.class, "abc");
		System.out.println(user);
		
		HibernateUtil.closeSession();
	}
}
